<#include "/java_copyright.include">
<#assign className = table.className>   
<#assign classNameLower = className?uncap_first> 
package ${basepackage}.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.util.ArrayList;
import java.util.List;
import javax.validation.Valid;
import org.springframework.validation.BindingResult;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.github.pagehelper.PageInfo;
import my.mybatis.common.exception.BaseException;
import my.mybatis.common.request.BaseRequestParam;
import my.mybatis.common.response.InfoResult;
import my.mybatis.common.response.ListResult;
import my.mybatis.common.response.PageResult;
import my.mybatis.common.request.BaseStringIds;
import my.mybatis.common.util.CheckData;
import my.mybatis.common.util.PageInfoToResult;
import ${basepackage}.dto.${className};
import ${basepackage}.service.${className}Service;
/**
<#include "/java_description.include">
 */
@RestController
@RequestMapping(value = "${classNameLower}")
@Api(value = "${classNameLower}", description = "${className}接口")
public class ${className}Controller{
    private static final Logger logger = LoggerFactory.getLogger(${className}Controller.class);
    private final ${className}Service ${classNameLower}Service;

	@Autowired
	public ${className}Controller(${className}Service ${classNameLower}Service)
	{
		this.${classNameLower}Service = ${classNameLower}Service;
	}
	
    @ApiResponses(value = {@ApiResponse(code = 200, message = "保存${className}成功")})
    @ApiOperation(value = "save", notes = "保存${className}数据")
    @RequestMapping(value = "save", method = {RequestMethod.POST})
    public InfoResult<${className}> save(HttpServletRequest request,@Valid @RequestBody ${className} ${classNameLower}, BindingResult bindingResult) throws BaseException {
        InfoResult<${className}> result = new InfoResult<>();
		//校验数据
		CheckData.checkDateThrowException(bindingResult);
        result.setData(${classNameLower}Service.save(${classNameLower}));
        return result;
    }

    @ApiResponses(value = {@ApiResponse(code = 200, message = "删除${className}成功")})
    @ApiOperation(value = "delete", notes = "删除单条${className}")
    @RequestMapping(value = "delete", method = {RequestMethod.GET})
    public InfoResult<${className}> delete(HttpServletRequest request,${table.idColumn.javaType} id) throws BaseException {
        InfoResult<${className}> result = new InfoResult<>();
		${classNameLower}Service.deleteById(id);
        return result;
    }
    
	@ApiResponses(value = {@ApiResponse(code = 200, message = "编辑${className}成功")})
    @ApiOperation(value = "update", notes = "编辑${className}数据")
    @RequestMapping(value = "update", method = {RequestMethod.POST})
    public InfoResult<${className}> update(HttpServletRequest request,@Valid @RequestBody ${className} ${classNameLower}, BindingResult bindingResult) throws BaseException {
        InfoResult<${className}> result = new InfoResult<>();
		//校验数据
		CheckData.checkDateThrowException(bindingResult);
        ${classNameLower}Service.update(${classNameLower});
        return result;
    }

    @ApiResponses(value = {@ApiResponse(code = 200, message = "获取${className}详情成功")})
    @ApiOperation(value = "info", notes = "${className}详情")
    @RequestMapping(value = "info", method = {RequestMethod.GET})
    public InfoResult<${className}> info(HttpServletRequest request,${table.idColumn.javaType} id) throws BaseException{
        InfoResult<${className}> result = new InfoResult<>();
        result.setData(${classNameLower}Service.findById(id));
        return result;
    }
   
	@ApiResponses(value = {@ApiResponse(code = 200, message = "获取${className}列表成功")})
	@ApiOperation(value = "list", notes = "${className}列表")
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public ListResult<${className}> list(HttpServletRequest request, HttpServletResponse response, @RequestBody BaseRequestParam<${className}> param) throws BaseException{
		ListResult<${className}> result = new ListResult<${className}>();
		result.setData(${classNameLower}Service.list(param));
		return result;
	}
   
    @ApiResponses(value = {@ApiResponse(code = 200, message = "获取${className}列表成功")})
    @ApiOperation(value = "listPage", notes = "${className}列表")
	@RequestMapping(value = "/listPage", method = RequestMethod.POST)  
	public PageResult listPage(HttpServletRequest request,HttpServletResponse response,@RequestBody BaseRequestParam<${className}> param) throws BaseException{
 	    PageResult result = new PageResult();
		PageInfoToResult.pageInfoToResult(${classNameLower}Service.listPage(param),result);
		return result;
	}
}
